<template>
	<view class="content">
		<view class="detail">
			<image :src="detail.Avatar" style="width: 60px; height: 60px"></image>
			<text class="list-text"> &nbsp; {{ detail.Phone }} </text>
		</view>
		<view style="margin-left: 4%;">
			<text class="list-text">昵称：{{ detail.Nickname }}</text><br><br>
			<text class="list-text">用户名：{{ detail.Username }}</text><br><br>
			<text class="list-text">真实姓名：{{ detail.Realname }}</text><br><br>
			<text class="list-text">性别：{{ detail.Sex }}</text><br><br>
			<text class="list-text">年龄：{{ detail.Age }}岁</text><br><br>
			<text class="list-text">邮箱：{{ detail.Email }}岁</text><br><br>
			<text class="list-text">最后登录IP：{{ detail.Lastlogintime }}岁</text><br><br>
		</view>
		<button v-if="isButtonVisible" class="btn" @click="friendel(detail.fid)" >删 除 好 友</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				detail:{
					Avatar:'',
					Username:'',
					Nickname:'',
					Realname:'',
					Sex:'',
					Age:'',
					Phone:'',
					Email:'',
					Lastlogintime:'',
				},
				isButtonVisible: false,
				fid:0,
			}
		},
		onLoad(options) {
			this.fid = options.fid
			console.log("FID:"+options.fid)
			if (options.is_friend == 1) {
				this.isButtonVisible = true
			}
			console.log("是否好友:"+options.is_friend)
			this.friendetail(options.friend_id);
		},
		methods: {
			friendetail(friend_id){
				let that = this
				const jsloguser = uni.getStorageSync('jsloguser');		
				if(jsloguser){
					let jsluser = JSON.parse(jsloguser)
					uni.request({
					    url: that.$host+'/apiv/v1/friend/friend_detail', // 你的API接口地址
					    method: 'POST',
						header:{'content-type':'application/x-www-form-urlencoded;charset=utf-8','Token':jsluser.token},
					    data: {friend_id:friend_id},
					    success: (res) => {
							if(res.data.code == 200){
								this.detail = res.data.data.UserList
							}else{
								alert(res.data.msg)
							}
					    },
					    fail: (err) => {
							alert(err)
					    }
					});
				}
			},
			friendel(fid){
				fid = this.fid
				let that = this
				const jsloguser = uni.getStorageSync('jsloguser');		
				if(jsloguser){
					let jsluser = JSON.parse(jsloguser)
					uni.request({
					    url: that.$host+'/apiv/v1/friend/friend_del', // 你的API接口地址
					    method: 'POST',
						header:{'content-type':'application/x-www-form-urlencoded;charset=utf-8','Token':jsluser.token},
					    data: {fid:fid},
					    success: (res) => {
							if(res.data.code == 200){
								alert('成功')
							}else{
								alert('失败')
							}
					    },
					    fail: (err) => {
							alert(err)
					    }
					});
				}
			},
		}
	}
</script>

<style>
.detail{
	display: flex;
	align-items: center; /* 垂直居中 */
	margin-bottom: 10px; /* 列表项之间的间隔 */
	background:cornflowerblue;
	padding-left: 2%;
}
.btn {
    margin-top: 20rpx;
	width:60%;
	height:69rpx;
	line-height:69rpx;
	justify-content: center;
	background: #3E7BFA;
	bottom: 0;
	margin-top: 96%;
	margin-left: 20%;
}
</style>
